package cn.edu.java.thread.原子类;

import lombok.SneakyThrows;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerDemo {
    private static AtomicInteger atomicInteger = new AtomicInteger(0);


    static class IncrementTask implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                System.out.println(atomicInteger.getAndIncrement());
            }
        }
    }


    @SneakyThrows
    public static void main(String[] args) {
        new Thread(new IncrementTask()).start();
        new Thread(new IncrementTask()).start();

        Thread.sleep(100);

        System.out.println("AtomicInteger: " + atomicInteger);
    }
}

